package pro.cherish.knowledgescattered.system;


import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 该类用于自动初始化数据库配置到BaseConfig中，以便BaseConfig的子类调用
 */
@Component
class ConfigService {

    private static ConfigService systemConfigService;


    // private ISysconfLysService iSysconfLysService;

    //不允许实例化
    private ConfigService() {

    }

    static ConfigService getSystemConfigService() {
        return systemConfigService;
    }

    @PostConstruct
    public void inist() {
        systemConfigService = this;
        systemConfigService.inistConfigs();
    }

    /**
     * 根据 prefix 重置该 prefix 下所有设置
     *
     * @param prefix
     */
    public void reloadConfig(String prefix) {
        // List<SysconfLys> list = iSysconfLysService.list(new QueryWrapper<>());
        // for (SysconfLys item : list) {
        //     //符合条件，添加
        //     if (item.getKeyNameLys().startsWith(prefix)){
        //         BaseConfig.addConfig(item.getKeyNameLys(), item.getKeyValueLys());
        //     }
        // }
    }

    /**
     * 读取全部配置
     */
    private void inistConfigs() {
        // List<SysconfLys> list = iSysconfLysService.list(new QueryWrapper<>());
        // for (SysconfLys item : list) {
        //     BaseConfig.addConfig(item.getKeyNameLys(), item.getKeyValueLys());
        // }
    }
}